package projet_v1.simulation.events;

import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;

import projet_v1.Breed;
import projet_v1.Character;
import projet_v1.Human;
import projet_v1.simulation.Field;
import projet_v1.simulation.Location;
/**
 * 
 * The government decides to launch a chimical attack against the ennemies.
 * The attack area is bigger than a rescue operation for example.
 *
 * @author Romain Roufast
 *
 */

public class ChimicalAttack extends Event {

	private static final int TIME = 1100;
	private static final int DIMENSION = 6;

	/**
	 * Create a chimical attack
	 * @param impact, the impact of the attack (the start location)
	 */
	public ChimicalAttack(Location impact) {
		super(impact, DIMENSION, Event.IS_GOOD_FOR_HUMANITY);
	}

	/**
	 * When the chimical attack occurs vapires and zombies in the area must die.
	 */
	@Override
	public boolean happend(List<Character> characters, Field field) {

		boolean stillHasEffect = false;

		List<Location> l = new ArrayList<Location>();
		l = field.adjacentLocations(startLocation, dimension);
		l.add(startLocation);
		List<Character> characList = new ArrayList<Character>();
		for (Location loc : l) {
			Character c = field.getCharacterAt(loc);
			if(c!=null)
				characList.add(c);
		}
		for (Character character : characList) {
			if(!(character.getBreed().equals(Breed.HUMAN)))
				character.setLastAttackedBy(null);
				character.reduceHealthPoints(1000);
		}

		if ((TIME - duration) > 0) {
			duration++;
			stillHasEffect = true;
		}

		return stillHasEffect;
	}

}
